import {vec3, vec4 } from "gl-matrix";



export class Color{

    r = 0;
    g = 0;
    b = 0;
    a = 0;

    static _tmpVec4 = vec4.create();
    static _tmpVec3 = vec3.create();

    constructor(public hex:number) {
        this.r = hex >> 24 & 0xff;
        this.g = hex >> 16 & 0xff;
        this.b = hex >> 8 & 0xff;
        this.a = hex & 0xff;
    }

    toString(){
        return `r:${this.r},g:${this.g},b:${this.b},a:${this.a}`;
    }

    static fromARGB(value:number):Color{
        let a = value >> 24 & 0xff;
        let r = value >> 16 & 0xff;
        let g = value >> 8 & 0xff;
        let b = value & 0xff;
        return new Color(r << 24 | g << 16 | b << 8 | a);
    }

    toVec4f(){
        return vec4.set(Color._tmpVec4,this.r/255,this.g/255,this.b/255,this.a/255);
    }

    toVec3f(){
        return vec3.set(Color._tmpVec3,this.r/255,this.g/255,this.b/255);
    }

    setf(r:number,g:number,b:number,a:number){
        this.r = Math.floor(r * 255);
        this.g = Math.floor(g * 255);
        this.b = Math.floor(b * 255);
        this.a = Math.floor(a * 255);
        this.hex = this.r << 24 | this.g << 16 | this.b << 8 | this.a
    }
    seti(r:number,g:number,b:number,a:number){
        this.r = r;
        this.g = g;
        this.b = b;
        this.a = a;
        this.hex = r << 24 | g << 16 | b << 8 | a
    }
}


